#include "um.client.h"
#include "../NS/nameserver.h"

#include <iostream>
#include <string>

using namespace std;
using namespace TOB;
using namespace UM;

int main() {
  int menu;
  string username, password;
  Nameserver::IP nsip = 0x0100007F; //localhost
  
  cout << "Имя пользователя: \0";
  cin >> username;
  cout << "Пароль: \0";
  cin >> password;
  Client um = Client(nsip, username, password);
  
  do {
    cout << "Выберите действие:\n 1) Добавление пользователя\n 2) Удаление пользователя\n 3) Изменение поля\n 4) Выход\n>> \0";
    cin >> menu;
    if (menu == 4) break;
    string login, pass, policy, role, name;
    Code::Type respond;
    cout << "Login: \0";
    cin >> login;
    switch (menu) {
    case 1:
      cout << "Password: \0";
      cin >> pass;
      cout << "Role: \0";
      cin >> role;
      cout << "Policy: \0";
      cin >> policy;
      cout << "Name: \0";
      cin >> name;
      respond = um.createUser(login, pass, role, policy, name);
      if (respond == Code::Okay) cout << "Пользователь успешно создан" << endl;
      else cout << "Error" << endl;
      break;
    case 2:
      respond = um.deleteUser(login);
      if (respond == Code::Okay) cout << "Пользователь успешно удален" << endl;
      else cout << "Error" << endl;
      break;
    case 3:
      string field, value;
      cout << "Field: \0";
      cin >> field;
      cout << "Value: \0";
      cin >> value;
      respond = um.changeFieldByLogin(login, field, value);
      if (respond == Code::Okay) cout << "Данные изменены" << endl;
      else cout << "Error" << endl;
      break;
    }
  } while (true);
  return 0;
}
